/**
 * 
 */
package xx.services.management.rest;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;

import xx.entity.manage.UrlLog;
import xx.services.Passport;
import xx.services.management.inter.IUrlLogInterface;
import xx.services.util.Constants;

/**
 * 日志服务接口
 * 
 * @author dengjinye
 * @Path (Constants.RESTFUL_ROOT_PATH + "/management/log") 2013-7-8
 */
@Path(Constants.RESTFUL_ROOT_PATH + "/management/urllog")
public class UrlLogRest extends Passport implements IUrlLogInterface
{

    /**
     * @param request
     */
    public UrlLogRest(@Context
    HttpServletRequest request)
    {
        super(request);
        // TODO Auto-generated constructor stub
    }

    /*
     * (non-Javadoc)
     * @see xx.services.management.inter.ILogInterface#getLogById(long)
     */
    @Override
    @GET
    @Path("/{log_id}")
    public String getLogById(@PathParam("log_id")
    long logId)
    {
        try
        {
            UrlLog log = new UrlLog(qr, owner);
            log.setLogId(logId).load();
            return ok(log);
        }
        catch (SQLException e)
        {
            return error(e);
        }

    }

    /*
     * (non-Javadoc)
     * @see xx.services.management.inter.ILogInterface#getLogList()
     */
    @Override
    @GET
    @Path("/list")
    public String getLogList()
    {
        try
        {
            // String condition = this.getParameter("condition");
            UrlLog log = new UrlLog(qr, owner);
            List<UrlLog> list = log.getLogList(pageSize, pageNo, condition, orderField, fields);
            Map<String, Object> map = new HashMap<String, Object>();
            if (isTotal)
            {
                map.put(Constants.TOTAL, log.getCount(condition));
            }
            return ok(list, map);
        }
        catch (SQLException e)
        {
            return error(e);
        }
    }

}
